package com.nd.mobile.study.view.widget;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;

public class Loading {

	private Dialog mDialog;
	private Context mContext;
	private int mSemaphore;
	
	public Loading (Context context){
		mContext = context;
	}
	
	public void p() {
		mSemaphore++;
		if(null == mDialog) initDialog();
		mDialog.show();
	}

	public void v() {
		mSemaphore--;
		if(0 == mSemaphore && null !=mDialog) {
			mDialog.cancel();
		}
		
		if(0 > mSemaphore) {
			mSemaphore = 0;
//			ToastHelper.displayToastLong(mContext, "Loading:IllegalState");
		}
	}

	private void initDialog() {
		//TODO custom dialog
		mDialog = new ProgressDialog(mContext);
//		mDialog.setCancelable(false);
	}
}
